package com.clkj.xiuzheng.dao;

import com.clkj.xiuzheng.pojo.Product;
import com.clkj.xiuzheng.pojo.ProductStock;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;
import tk.mybatis.mapper.common.BaseMapper;
import tk.mybatis.mapper.common.Mapper;

import java.util.List;

@Repository
public interface ProductStockMapper extends Mapper<ProductStock> {
    @Select("select stock_id,product_id,bar_code,product_date,validity,warehouse_id,company_id,product_num,factory_id,product_unit from t_cl_productStock where product_id = #{productId}")
    ProductStock selectByProductId(@Param("productId") Integer productId);

    @Select("select a.*,b.product_name,b.product_img,b.format_name,c.factory_name  from t_cl_productStock a" +
            " left join t_cl_product b on a.product_id = b.product_id " +
            "left join t_cl_factory c on a.factory_id = c.factory_id " +
            "where  a.company_id =#{companyId} ")
    List<ProductStock> listAllProduct(@Param("companyId")Integer companyId);
    @Select("select * from t_cl_productStock where product_id = #{productId} and bar_code = #{barCode}")
    ProductStock selectProductItemNumByProductIdAndBarCode(@Param("productId") Integer productId, @Param("barCode") String barCode);

    @Select("update t_cl_productStock set product_num = #{productNum} where product_id = #{productId} and bar_code = #{barCode}")
    void updateProductNumByProductIdAndBarCode(@Param("productId") Integer productId, @Param("barCode") String barCode, @Param("productNum") Integer productNum);

    @Select("select * from t_cl_productStock where product_id = #{productId} and bar_code = #{barCode}")
    ProductStock selectByProductIdAndBarCode(@Param("productId") Integer productId, @Param("barCode") String barCode);
}
